<template>
	<view>
		<xw-empty :isShow="emptyShow" text="暂无相关数据" textColor="#777777"></xw-empty>
		<view class="" v-if="emptyShow==false">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" top="0" bottom="0" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 分页数据 -->
				<view class="cu-card article no-card">
					<view class="cu-item" style="padding-bottom: 0rpx;" v-for="item in dataList" :key="item.id" @tap="goDetail(item)">
						<view class="title">
							<view class="text-cut">{{item.title}}</view>
						</view>
						<view class="content">
							<view class="desc margin-right-sm">
								<view class="text-gray flex align-center justify-between" style="font-size: 12px;">
									<view class="flex align-center justify-between">
										<view class="cu-avatar round sm margin-right-sm" :style="{backgroundImage: 'url('+ item.portrait +')'}"></view>
										<view class="text-grey text-sm text-bold">{{item.realname}}</view>
									</view>
								</view>
								<view class="text-content" style="color: #333333;">{{item.content}}</view>
								<!-- <view class="text-content" style="color: #333333;">内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容</view> -->
							</view>
							<!-- <image src="https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg" mode="aspectFill"></image> -->
							<image v-if="item.pics.length >= 1" :src="item.pics[0]"  mode="aspectFill"></image>
						</view>
						<view class="text-sm flex justify-between" style="padding: 10upx 30upx 10upx;color: #afafaf">
							<view>
								<text class="cuIcon-attentionfill margin-lr-xs"></text>{{item.viewCount}}
								<text class="cuIcon-appreciatefill margin-lr-xs"></text> {{item.zanNum}}
								<text class="cuIcon-messagefill margin-lr-xs"></text> {{item.commentNum}}
							</view>
							<view class="text-sm">{{item.time}}</view>
						</view>
						<view class="padding-bottom-sm bg-gray"></view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue";
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import xwEmpty from '@/components/xw-empty/xw-empty';
	import dateUtils from '@/common/util/dateUtils.js';
	export default {
		mixins: [MescrollMixin],
		components: {
			xwEmpty,
			MescrollBody
		},
		data() {
			return {
				downOption: {
					auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
				},
				addList: [], //新增微博
				top: 0, //提示,到顶部的距离0

				emptyShow: false, //true显示，false隐藏
				dataList: [], // 数据列表
			}
		},
		methods: {
			goDetail: function(e) {
				this.$Router.push({
					name: 'nswd_comment',
					params: e
				})
			},
			downCallback() {
				this.mescroll.resetUpScroll();
			},
			upCallback(page) {
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				uni.request({
					url: this.$config.apiUrl + "/questionController/list/" + pageNum + "/" + pageSize,
					success: (data) => {
						//console.log(data)
						if (data.data.ok) {
							let curPageData = data.data.data;
							let curPageLen = curPageData.length;
							// 接口返回的是否有下一页 (true/false)
							let hasNext
							if (curPageLen < pageSize) {
								hasNext = false;
							} else {
								hasNext = true;
							}

							//设置列表数据
							if (page.num == 1) this.dataList = [];
							for (var i = 0; i < curPageData.length; i++) {
								let time = dateUtils.dateFormat('YYYY-mm-dd', new Date(curPageData[i].time));
								//图片
								let imgUrl = [];
								let imgList = [];
								imgUrl = (curPageData[i].picturesUrl == null || curPageData[i].picturesUrl == "") ? '' : curPageData[
									i].picturesUrl.split(",");
								for (var j = 0; j < imgUrl.length; j++) {
									if (imgUrl[j] != '' && imgUrl[j] != null) {
										var imgSerUrl = this.$config.imgUrl + '/' + imgUrl[j];
										imgList.push(imgSerUrl);
									}
								}
								curPageData[i].pics = imgList;
								curPageData[i].time = time;
								curPageData[i].portrait = this.$config.imgUrl + '/' + curPageData[i].portrait 
							}
							this.dataList = this.dataList.concat(curPageData); //追加新数据
							//console.log(this.dataList)

							this.mescroll.endSuccess(curPageLen, hasNext);
							if (this.dataList.length > 0) {
								this.emptyShow = false;
							} else {
								this.emptyShow = true;
							}
						}
					},
					fail: () => {
						this.mescroll.endErr()
					}
				})
			}
		}
	}
</script>
<style>
	.cu-card.article>.cu-item .title {
		font-size: 30upx;
		font-weight: 900;
		color: #333333;
		line-height: 60upx;
		padding: 0 30upx;
	}
	
	.cu-card.article>.cu-item .content>image {
		width: 180upx;
		height: 4.8em;
		margin-right: 20upx;
		border-radius: 6upx;
	}
	
	.cu-card.article>.cu-item .content .desc {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	
	.cu-card.article>.cu-item .content .text-content {
		font-size: 26upx;
		color: #888;
		height: 3.2em;
		overflow: hidden;
	}
</style>
